package com.xuwang.service.impl;

import com.xuwang.mapper.CaseFilingMapper;
import com.xuwang.pojo.CaseFiling;
import com.xuwang.vo.CaseFilingVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import com.xuwang.service.CaseFilingService;

/**
 * 案件备案表服务实现
 *
 * @ClassName CaseFilingServiceImpl
 * @Description TODO
 * @Author OuJunchen
 * @Date 2021/9/14 上午10:27
 * @Version 1.0
 */
@Service
public class CaseFilingServiceImpl implements CaseFilingService {

    @Resource
    private CaseFilingMapper caseFilingMapper;

    @Override
    public Map<String, Object> deleteByPrimaryKey (String id) {
        String[] idArray = id.split(",");
        List<String> list = new ArrayList<>();
        list.addAll(Arrays.asList(idArray));
        caseFilingMapper.deleteByPrimaryKey(list);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);   // 前端端分离时，前端人员会首先判断code值是否满足200，如果不是200，则提醒用户失败
        map.put("msg", "删除成功");
        return map;
    }

    @Override
    public Map<String, Object> insert (CaseFiling record) {
        record.setRecordNumber(String.valueOf(System.currentTimeMillis()));
        record.setFilingDate(new Date());
        caseFilingMapper.insert(record);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);   // 前端端分离时，前端人员会首先判断code值是否满足200，如果不是200，则提醒用户失败
        map.put("msg", "新增成功");
        return map;
    }

    @Override
    public int insertOrUpdate (CaseFiling record) {
        return caseFilingMapper.insertOrUpdate(record);
    }

    @Override
    public int insertOrUpdateSelective (CaseFiling record) {
        return caseFilingMapper.insertOrUpdateSelective(record);
    }

    @Override
    public Map<String, Object> insertSelective (CaseFiling record) {
        record.setRecordNumber(String.valueOf(System.currentTimeMillis()));
        record.setFilingDate(new Date());
        caseFilingMapper.insertSelective(record);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);   // 前端端分离时，前端人员会首先判断code值是否满足200，如果不是200，则提醒用户失败
        map.put("msg", "新增成功");
        return map;
    }

    @Override
    public CaseFiling selectByPrimaryKey (Integer id) {
        return caseFilingMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective (CaseFiling record) {
        return caseFilingMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey (CaseFiling record) {
        return caseFilingMapper.updateByPrimaryKey(record);
    }

    @Override
    public int updateBatch (List<CaseFiling> list) {
        return caseFilingMapper.updateBatch(list);
    }

    @Override
    public int updateBatchSelective (List<CaseFiling> list) {
        return caseFilingMapper.updateBatchSelective(list);
    }

    @Override
    public int batchInsert (List<CaseFiling> list) {
        return caseFilingMapper.batchInsert(list);
    }

    @Override
    public Map<String, Object> selectAll (int page, int limit, CaseFilingVo caseFilingVo) throws ParseException {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 500);
        map.put("msg", "查询失败!");
        page = (page - 1) * limit;
        CaseFiling caseFiling = new CaseFiling();
        BeanUtils.copyProperties(caseFilingVo, caseFiling);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date = null;
        date = caseFilingVo.getFilingDate();
        if (date != null && !"".equals(date.trim())) {
            date = sdf.format(new Date(Long.parseLong(caseFilingVo.getFilingDate())));
        }
        List<CaseFiling> caseFilingList = caseFilingMapper.selectAll(page, limit, date, caseFiling);
        if (caseFilingList != null) {
            map.put("code", 0);
            map.put("msg", "查询成功!");
            map.put("pageCount", caseFilingList.size());
            map.put("data", caseFilingList);
        }
        return map;
    }

}





